package cn.neusoft.yuejian307.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.squareup.picasso.Picasso;

import java.util.List;

import cn.neusoft.yuejian307.R;
import cn.neusoft.yuejian307.bean.NewBean;

import static cn.neusoft.yuejian307.GloableVirable.IMG_URL;



public class NewsAdapter extends  RecyclerView.Adapter< RecyclerView.ViewHolder> {
    private Context mContext;
    private List<NewBean> mList;
    public LayoutInflater mLayoutInflater;

    public NewsAdapter(Context mContext, List<NewBean> List) {
        this.mContext = mContext;
        this.mList = List;
        mLayoutInflater = LayoutInflater.from(mContext);
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.cardview_news, parent, false);
        NewsAdapter.ViewHolder v = new NewsAdapter.ViewHolder(view);

        return v;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        final NewBean club = (NewBean) mList.get(position);
        if (null == club)
            return;
        NewsAdapter.ViewHolder viewHolder = (NewsAdapter.ViewHolder) holder;
        viewHolder.tv_send_content.setText(club.getContent());
        if(club.getUser_picture()!=null) {
            Picasso.with(mContext).load(IMG_URL+club.getUser_picture()).into(viewHolder.img_photo);
        }

    }

    @Override
    public int getItemCount() {
        return mList.size();
    }


    public class ViewHolder extends RecyclerView.ViewHolder {
        TextView tv_send_content;
        ImageView img_photo;

        public ViewHolder(View itemView) {
            super(itemView);
            tv_send_content = (TextView) itemView.findViewById(R.id.tv_send_content);
            img_photo = (ImageView) itemView.findViewById(R.id.img_photo);

        }
    }
}
